package assem;

import temp.LabelList;
import temp.TempList;
import temp.TempMap;

public class OPER extends Instr {
	TempList dst, src;
	Targets labels = null;

	public OPER(String a, TempList d, TempList s, LabelList l) {
		assem = a;
		dst = d;
		src = s;
		labels = new Targets(l);
	}
	
	public OPER(String a, TempList d, TempList s) {
		assem = a;
		dst = d;
		src = s;
	}
	
	public TempList def() {
		return dst;
	}

	public String format(TempMap m) {
		String out = new String(assem);
		int i = 0;
		for (TempList tl = dst; tl != null; tl = tl.tail) {
			try {
			out = out.replace("\'d" + i, m.tempMap(tl.head));
			} catch (Exception e) {
				e.printStackTrace();
			}
			i++;
		}
		i = 0;
		for (TempList tl = src; tl != null; tl = tl.tail) {
			out = out.replace("'s" + i, m.tempMap(tl.head));
			i++;
		}
		return out;
	}

	public Targets jumps() {
		return labels;
	}

	public TempList use() {
		return src;
	}

}
